//
//  OponionViewController.m
//  project_delicious
//
//  Created by dlios on 15-4-2.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "OponionViewController.h"

@interface OponionViewController ()
@property (nonatomic, retain) NSString *str;
@property (nonatomic, retain) UITextField *textField;
@property (nonatomic, retain) UITextView *textView;
@end

@implementation OponionViewController
- (void)dealloc
{
    [_textView release];
    [_textField release];
    [_str release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"IMG_1345.JPG"]];
    //self.title = @"请留下你的宝贵意见";

    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, HEIGHT / 4, WIDTH - 20, HEIGHT / 10)];
    self.textField.borderStyle = UITextBorderStyleRoundedRect;
    self.textField.placeholder = @"请留下您的宝贵意见,谢谢";
    self.textField.textAlignment = NSTextAlignmentLeft;
    self.str = self.textField.text;
    self.textField.clearsOnBeginEditing = YES;
    
    self.textField.clearButtonMode = UITextFieldViewModeAlways;
    [self.view addSubview:self.textField];
    [_textField release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(50, HEIGHT / 4 + HEIGHT / 10 + 10, 70, 70);
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(certainButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //button.backgroundColor = [UIColor redColor];
    [self.view addSubview:button];
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    button1.frame = CGRectMake(self.view.frame.size.width-120, HEIGHT / 4 + HEIGHT / 10 + 10, 70, 70);
    [button1 setTitle:@"返回" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(cancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    //button1.backgroundColor = [UIColor yellowColor];
    [self resignFirstResponder];
}

//确定按钮
- (void)certainButtonAction:(UIButton *)button
{
    if (self.textField.text.length != 0) {
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"发送成功" message:@"谢谢您的宝贵意见, 我们虚心接受您的意见" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertView show];
        [self.view addSubview:alertView];
        [alertView release];
        [self.textField resignFirstResponder];
    }

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    self.textField.text = @"";
}
//取消按钮
- (void)cancelButtonAction:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self resignFirstResponder];
    return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
